package com.etc.demo.controller.quartz;

import com.etc.utils.QuartzUtil;
import com.etc.demo.service.job.QuartzJob1;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * 测试方法
    @author Chen
    @since 2021/1/15 - 12:29
*/

@RestController
public class JobController {

	// 将容器中的对象注入进来
	@Autowired
	@Qualifier("job1")
	QuartzJob1 job;

	@GetMapping("quartz")
	public String test() throws SchedulerException, ParseException {
		// 开启两条定时任务分别为3秒执行一次，5秒执行一次
		QuartzUtil.schedule(job.getClass(), "0/5 * * ? * *", "trigger1");
		QuartzUtil.schedule(job.getClass(), "0/3 * * ? * *", "trigger2");
		return "test";
	}

}